package gw.com.android.app.dispatch;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;

import java.util.Map;

import gw.com.android.model.ConfigType;
import gw.com.android.terminal.GTSDataListener;
import gw.com.android.ui.MainActivity;
import gw.com.android.ui.me_concern.MyConcernActivity;
import gw.com.android.ui.me_post.MyPostActivity;
import gw.com.android.ui.onlive.MainLiveFragment;
import www.com.library.app.AppActivities;
import www.com.library.app.ObjectSessionStore;

/**
 * 分发“圈子”模块的业务处理类
 * hxgts2://discuss/
 *
 * @author jett
 * @since 2018-07-05.
 */
public class DiscussDispatch implements Dispatch {

    @Override
    public boolean handle(Activity activity, String path, Map<String, String> params) {
        if ("tab".equals(path)) {
            toDiscussTab();
            return true;
        } else if ("follows".equals(path)) {
            openFollow(activity);
            return true;
        } else if ("my_posts".equals(path)) {
            openMyPost(activity);
            return true;
        }
        return false;
    }

    /**
     * hxgts2://discuss/follows/
     */
    private void openFollow(Context context) {
        context.startActivity(new Intent(context, MyConcernActivity.class));
    }

    /**
     * hxgts2://discuss/my_posts/
     */
    private void openMyPost(Context context) {
        context.startActivity(new Intent(context, MyPostActivity.class));
    }

    /**
     * hxgts2://discuss/tab/
     */
    private void toDiscussTab() {
        AppActivities.getSingleton().popAllActivityExceptOne(MainActivity.class.getSimpleName());
        MainActivity mainActivity = (MainActivity) ObjectSessionStore.getObject(MainActivity.class.getSimpleName() + GTSDataListener.mainNum);
        if (mainActivity != null) {
            mainActivity.setTabFragment(ConfigType.TAB_ONLIVE_TAG, String.valueOf(MainLiveFragment.DISCUSS));
        }
    }

}
